package com.xm_jd.controller.jiesuan;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xm_jd.model.dao.BalanceDao;
import com.xm_jd.model.entitys.tb_sh;
import com.xm_jd.model.entitys.user;
import com.xm_jd.utils.BaseServlet;

/**
 * Servlet implementation class AddressServlet
 */
@WebServlet("/addadreess")
public class AddAddressServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddAddressServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//�����ַ���
		request.setCharacterEncoding("utf-8");
		String shuor=request.getParameter("shuor");
		String xiadi=request.getParameter("xiadi");
		String phonea=request.getParameter("phonea");
		String ss=request.getParameter("ssq");
		String moren=request.getParameter("mo");
		//��sessionȡ�û���
		BalanceDao dao =new BalanceDao();
		
		int j=dao.updatemoren(1);
		System.out.println(j);
		String a="0";
		if(!"".equals(moren)){
			a="1";
		}
		user aa=(user) request.getSession().getAttribute("users");
		tb_sh s=new tb_sh(1,ss,xiadi,shuor,phonea,a,aa.getUser_id());
		
		
		tb_sh shiti=new tb_sh();
		shiti.setSh_name(shuor);
		shiti.setSh_xxdz(xiadi);
		shiti.setSh_phone(phonea);
		shiti.setSh_address(ss);
		shiti.setSh_ismr("0");
		shiti.setSh_user_id(aa.getUser_id());

		dao.addgood(shiti);
		
		//List<tb_sh> list = new BalanceDao().selectSh(1);
		//request.getSession().setAttribute("address", list);
		//request.getRequestDispatcher("jsps/address.jsp").forward(request, response);
		//response.sendRedirect("jsps/address.jsp");
		response.sendRedirect("/addresslist");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
